<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/astronaut32.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/astronaut16.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">

<link rel="stylesheet" href="fonts.googleapis.com/css?family=EB Garamond:300,300italic,400,400italic,700,700italic|Cinzel Decorative:300,300italic,400,400italic,700,700italic|Noto Serif SC:300,300italic,400,400italic,700,700italic|Source Code Pro:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">
<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.css">
  <link rel="stylesheet" href="/lib/pace/pace-theme-pace-theme-minimal.min.css">
  <script src="/lib/pace/pace.min.js"></script>

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"fat_fat_where_are_you.gitee.io","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":true,"style":"mac"},"back2top":{"enable":false,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":true,"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

<link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@500&display=swap" rel="stylesheet">
  <meta name="description" content="JavaScript基础语法 这篇笔记主要讲了JavaScript函数，变量作用域，预解析，对象，内部对象以及两种数据类型这篇笔记有很多JavaScript的特性，所以可以认真看下这篇笔记是初学者写下的笔记，如有错误，欢迎前来指正">
<meta property="og:type" content="article">
<meta property="og:title" content="JavaScript 基础语法 3">
<meta property="og:url" content="http://fat_fat_where_are_you.gitee.io/archives/b8089044.html">
<meta property="og:site_name" content="肥肉啊肥肉你在哪">
<meta property="og:description" content="JavaScript基础语法 这篇笔记主要讲了JavaScript函数，变量作用域，预解析，对象，内部对象以及两种数据类型这篇笔记有很多JavaScript的特性，所以可以认真看下这篇笔记是初学者写下的笔记，如有错误，欢迎前来指正">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-08-06T06:35:46.000Z">
<meta property="article:modified_time" content="2020-08-06T06:35:46.000Z">
<meta property="article:author" content="肥肉啊肥肉你在哪">
<meta property="article:tag" content="JavaScript">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://fat_fat_where_are_you.gitee.io/archives/b8089044.html">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>
<link rel="stylesheet" type="text/css" href="/css/injector/main.css"><link rel="preload" as="style" href="/css/injector/light.css"><link rel="preload" as="style" href="/css/injector/dark.css">
  <title>JavaScript 基础语法 3 | 肥肉啊肥肉你在哪</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

  <script src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome/css/font-awesome.min.css">

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">肥肉啊肥肉你在哪</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
        <li class="menu-item menu-item-movies">

    <a href="/movies/" rel="section"><i class="fa fa-film fa-fw"></i>观影</a>

  </li>
        <li class="menu-item menu-item-books">

    <a href="/books/" rel="section"><i class="fa fa-book fa-fw"></i>阅读</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" placeholder="搜索..." spellcheck="false" type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="reading-progress-bar"></div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://fat_fat_where_are_you.gitee.io/archives/b8089044.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/touxiang.gif">
      <meta itemprop="name" content="肥肉啊肥肉你在哪">
      <meta itemprop="description" content>
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="肥肉啊肥肉你在哪">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          JavaScript 基础语法 3
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-08-06 14:35:46" itemprop="dateCreated datePublished" datetime="2020-08-06T14:35:46+08:00">2020-08-06</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%89%8D%E7%AB%AF/" itemprop="url" rel="index"><span itemprop="name">前端</span></a>
                </span>
            </span>

          
          
          <br>
            <span id="/archives/b8089044.html" class="post-meta-item leancloud_visitors" data-flag-title="JavaScript 基础语法 3" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/archives/b8089044.html#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/archives/b8089044.html" itemprop="commentCount"></span>
    </a>
  </span>
  
  <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>9.7k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>9 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h1 id="JavaScript 基础语法"><a href="#JavaScript 基础语法" class="headerlink" title="JavaScript 基础语法"></a>JavaScript 基础语法</h1><blockquote>
<p>这篇笔记主要讲了 JavaScript 函数，变量作用域，预解析，对象，内部对象以及两种数据类型 <br> 这篇笔记有很多 JavaScript 的特性，所以可以认真看下 <br> 这篇笔记是初学者写下的笔记，如有错误，欢迎前来指正</p>
</blockquote>
<span id="more"></span>

<h2 id="JavaScript 函数"><a href="#JavaScript 函数" class="headerlink" title="JavaScript 函数"></a>JavaScript 函数</h2><ul>
<li>函数：重复使用某些代码，实现代码复用</li>
<li>函数命名仍然是小驼峰命名</li>
<li>函数可以调用另一个函数 (可以先使用后定义)</li>
<li>函数里面还可以嵌套函数</li>
</ul>
<h3 id="JavaScript 函数使用"><a href="#JavaScript 函数使用" class="headerlink" title="JavaScript 函数使用"></a>JavaScript 函数使用</h3><ul>
<li>   代码示例：</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 声明 </span></span><br><span class="line"><span class="function"><span class="keyword">function</span> 函数名(<span class="params"> 形参<span class="number">1</span>, 形参<span class="number">2</span></span>) </span>&#123;</span><br><span class="line">    <span class="comment">// 函数体</span></span><br><span class="line">    <span class="keyword">return</span> 参数;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> 接收变量 = 函数名(实参<span class="number">1</span>, 实参<span class="number">2</span>); <span class="comment">// 调用</span></span><br></pre></td></tr></table></figure>

<ul>
<li><p><span style="background-color :yellow"> 注意：不需要声明形参，可以直接写一个参数名</span></p>
</li>
<li><p>形参的个数和实参不匹配也可以：</p>
<ul>
<li>实参个数 &gt; 形参个数：只读取形参的个数</li>
<li>实参个数 &lt; 形参个数：<span style="background-color :yellow">没有值的形参默认为 undefined</span></li>
</ul>
</li>
<li><p>return 终止函数，语句之后的代码不会被执行</p>
</li>
<li><p>return 只能返回一个值，返回多个值以最后一个值为准</p>
</li>
<li><p>想要返回多个值，可以使用数组作为返回值</p>
</li>
<li><p>函数没有 return 的话，返回的值是 undefined</p>
</li>
</ul>
<h3 id="arguments 使用 -★"><a href="#arguments 使用 -★" class="headerlink" title="arguments 使用(★)"></a>arguments 使用(★)</h3><ul>
<li>   arguments：所有函数都内置了一个 arguments 对象，存储了所有实参</li>
<li>   可以用于所有的函数，包括对象内的函数</li>
<li>   代码示例：</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">test</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="built_in">arguments</span>);</span><br><span class="line">    <span class="comment">// 输出[1,2,3]</span></span><br><span class="line">&#125;</span><br><span class="line">test(<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>);</span><br></pre></td></tr></table></figure>

<ul>
<li>arguments 展示的是 <code> 伪数组</code>，所以可以遍历<ul>
<li>可以使用 length 属性</li>
<li>可以用下标索引</li>
<li>不同点：没有数组的 push 和 pop 方法</li>
</ul>
</li>
</ul>
<h4 id="arguments 使用案例"><a href="#arguments 使用案例" class="headerlink" title="arguments 使用案例"></a>arguments 使用案例</h4><ul>
<li>   求未知个数的数组里的最大值</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">getMax</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="keyword">var</span> max = <span class="number">0</span>;</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">var</span> i = <span class="number">0</span>; i &lt; <span class="built_in">arguments</span>.length; i++) &#123;</span><br><span class="line">        <span class="keyword">if</span> (max &lt; <span class="built_in">arguments</span>[i]) &#123;</span><br><span class="line">            max = <span class="built_in">arguments</span>[i];</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> max;</span><br><span class="line">&#125;</span><br><span class="line"><span class="built_in">console</span>.log(getMax(<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">7</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>));</span><br><span class="line"><span class="comment">// 输出 7</span></span><br></pre></td></tr></table></figure>

<h3 id="函数声明两种方式"><a href="# 函数声明两种方式" class="headerlink" title="函数声明两种方式"></a>函数声明两种方式</h3><ul>
<li>   直接声明 (function 方法)：</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">fn</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">&#125;</span><br><span class="line">fn();</span><br></pre></td></tr></table></figure>

<ul>
<li>   函数表达式 (匿名函数)：</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> 变量名 = <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;&#125;;</span><br><span class="line"><span class="comment">// 调用 </span></span><br><span class="line"> 变量名();</span><br></pre></td></tr></table></figure>

<h2 id="变量作用域（★）"><a href="# 变量作用域（★）" class="headerlink" title="变量作用域（★）"></a>变量作用域（★）</h2><ul>
<li><p>es6 版本之前：全局变量，局部变量</p>
<ul>
<li>全局变量：作用于 script 标签之间或者一个 js 文件</li>
<li>局部变量：在函数内部声明的变量</li>
</ul>
</li>
<li><p><span style="background-color :yellow">注意：全局变量和局部变量名字可以相同，不会起冲突</span></p>
</li>
<li><p><span style="background-color :yellow">如果在同一个作用域下名字相同，后面的值会把前面的值覆盖</span></p>
</li>
<li><p>特例！</p>
</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">fun</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="keyword">var</span> num1 = <span class="number">10</span>;</span><br><span class="line">    num2 = <span class="number">20</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="built_in">console</span>.log(num1);</span><br><span class="line"><span class="comment">// 报错，变量未定义</span></span><br><span class="line"><span class="built_in">console</span>.log(num2);</span><br><span class="line"><span class="comment">// 可以直接输出</span></span><br></pre></td></tr></table></figure>

<ul>
<li><span style="background-color :yellow">注意：在函数内部没有声明直接赋值的变量也属于全局变量</span></li>
<li>函数的形参也属于 <code> 局部变量</code></li>
</ul>
<h3 id="块级作用域 - 新属性"><a href="# 块级作用域 - 新属性" class="headerlink" title="块级作用域 (新属性)"></a>块级作用域 (新属性)</h3><ul>
<li>现阶段没有块级作用域</li>
<li>在一个花括号里面的作用域</li>
<li>注意！和其他语言不同，JavaScript 在 if，for 里面定义的变量都是可以全局使用的，只有函数里声明的变量才是局部变量</li>
</ul>
<h3 id="作用域链"><a href="# 作用域链" class="headerlink" title="作用域链"></a>作用域链</h3><ul>
<li>   内部函数可以访问外部函数</li>
<li>   代码示例：</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> num = <span class="number">10</span>;</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">fn</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="keyword">var</span> num = <span class="number">20</span>;</span><br><span class="line">    <span class="function"><span class="keyword">function</span> <span class="title">fun</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">        <span class="built_in">console</span>.log(num);</span><br><span class="line">        <span class="comment">// 问题：这时输出哪个 num 值?</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// 输出 20</span></span><br></pre></td></tr></table></figure>

<ul>
<li>这时输出离变量最近的声明 (<code>就近原则</code>)</li>
</ul>
<h2 id="JavaScript 预解析 -★"><a href="#JavaScript 预解析 -★" class="headerlink" title="JavaScript 预解析(★)"></a>JavaScript 预解析(★)</h2><ul>
<li>   情景一：</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">console</span>.log(num);</span><br><span class="line"><span class="keyword">var</span> num = <span class="number">10</span>;</span><br><span class="line"><span class="comment">// 输出结果 undefined</span></span><br></pre></td></tr></table></figure>

<ul>
<li>   情景二：</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">fn();</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">fn</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="string">&#x27;test&#x27;</span>);</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// fn();</span></span><br><span class="line"><span class="comment">// 无论 fn 在定义函数前面还是定义函数后面，都可以正常输出 test</span></span><br></pre></td></tr></table></figure>

<ul>
<li>   情景三：</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">fn(); <span class="comment">// 报错</span></span><br><span class="line"><span class="keyword">var</span> fn = <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="string">&#x27;test&#x27;</span>);</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// 这里只提升了 var fn;</span></span><br><span class="line"><span class="comment">// js 以为他是个变量，所以会报错</span></span><br></pre></td></tr></table></figure>

<ul>
<li><p>运行 js 代码时分为两步：1. 预解析 2. 代码执行</p>
<ul>
<li>预解析：会把所有的 var 和 function 提升到作用域的最前面</li>
<li>代码执行：按照代码执行的顺序执行</li>
</ul>
</li>
<li><p>注意！预解析只提升变量声明，不提升变量赋值</p>
</li>
<li><p>函数提升的时候把 function 声明的函数 <code> 整个 </code> 提升到最前面 (所以即使先使用后声明也可以正常运行)</p>
</li>
</ul>
<h3 id="预解析实例"><a href="# 预解析实例" class="headerlink" title="预解析实例"></a>预解析实例</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> num = <span class="number">10</span>;</span><br><span class="line">fun();</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">fun</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="built_in">console</span>.log(num);</span><br><span class="line">    <span class="keyword">var</span> num = <span class="number">20</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// 输出结果 undefined</span></span><br></pre></td></tr></table></figure>

<ul>
<li>   解析：最外层 function 会提升到最前面，然后 <code>fun()</code> 调用这个函数的时候，函数预解析：</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">fun</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="keyword">var</span> num;</span><br><span class="line">    <span class="built_in">console</span>.log(num);</span><br><span class="line">    num = <span class="number">20</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li><p>所以输出的是 undefined</p>
</li>
<li><p><span style="background-color :yellow">特例！var a = b = c = 9 相当于 var a = 9; b = 9; c = 9;</span></p>
</li>
<li><p>所以这里的 b 和 c 直接赋值，相当于全局变量</p>
</li>
</ul>
<h2 id="JavaScript 对象"><a href="#JavaScript 对象" class="headerlink" title="JavaScript 对象"></a>JavaScript 对象</h2><ul>
<li>对象是指一个具体的东西，而不是泛指</li>
</ul>
<h3 id="创建对象的三种方式 - 自定义对象"><a href="# 创建对象的三种方式 - 自定义对象" class="headerlink" title="创建对象的三种方式 (自定义对象)"></a>创建对象的三种方式 (自定义对象)</h3><ul>
<li>在对象里面声明的叫属性或方法</li>
</ul>
<blockquote>
<p>java 里面的函数都是写在类内的，所以叫方法</p>
</blockquote>
<h4 id="直接创建对象"><a href="# 直接创建对象" class="headerlink" title="直接创建对象"></a>直接创建对象</h4><ul>
<li>   代码示例：</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> obj = &#123;&#125;; <span class="comment">// 创建一个空对象</span></span><br><span class="line"><span class="keyword">var</span> obj2 = &#123; <span class="comment">// 这里是直接新建了一个对象叫 obj2</span></span><br><span class="line">    <span class="attr">name</span> : <span class="string">&#x27; 菜鸟小铭 &#x27;</span>, <span class="comment">// 注意！这里是逗号</span></span><br><span class="line">    <span class="attr">age</span> : <span class="number">18</span> ,</span><br><span class="line">    <span class="attr">hello</span>: <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">        <span class="built_in">console</span>.log(<span class="string">&#x27;Hello&#x27;</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// 调用对象</span></span><br><span class="line"><span class="built_in">console</span>.log(obj2.name);</span><br><span class="line"><span class="comment">// 另一种方法</span></span><br><span class="line"><span class="built_in">console</span>.log(obj2[<span class="string">&#x27;age&#x27;</span>]);</span><br><span class="line"><span class="comment">// 调用方法</span></span><br><span class="line">obj2.hello();</span><br></pre></td></tr></table></figure>

<ul>
<li>注意！里面用的是冒号，多个属性用逗号隔开</li>
<li>方法后面跟的是匿名函数</li>
</ul>
<h4 id="利用 new-object 创建对象"><a href="# 利用 new-object 创建对象" class="headerlink" title="利用 new object 创建对象"></a>利用 new object 创建对象</h4><ul>
<li>   代码示例：</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> obj = <span class="keyword">new</span> <span class="built_in">Object</span>(); <span class="comment">// 创建一个空对象</span></span><br><span class="line"><span class="comment">// 然后追加属性和方法</span></span><br><span class="line">obj.name = <span class="string">&#x27; 代码小铭 &#x27;</span>;</span><br><span class="line">obj.age = <span class="number">18</span>;</span><br><span class="line">obj.Hello = <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="string">&#x27;Hello&#x27;</span>);</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// 调用和上面的一样</span></span><br><span class="line"><span class="built_in">console</span>.log(obj.name);</span><br><span class="line"><span class="built_in">console</span>.log(obj[<span class="string">&#x27;age&#x27;</span>]);</span><br><span class="line">obj.hello();</span><br></pre></td></tr></table></figure>

<ul>
<li><span style="background-color :yellow">注意！Object 必须要大写</span></li>
</ul>
<h4 id="利用构造函数创建对象 -★"><a href="# 利用构造函数创建对象 -★" class="headerlink" title="利用构造函数创建对象 (★)"></a> 利用构造函数创建对象(★)</h4><ul>
<li>   最接近其他语言的方法 (类似于类)</li>
<li>   代码示例：</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">Student</span>(<span class="params">name,age,sex</span>) </span>&#123;</span><br><span class="line">    <span class="built_in">this</span>.name = name;</span><br><span class="line">    <span class="built_in">this</span>.age = age;</span><br><span class="line">    <span class="built_in">this</span>.sex = sex;</span><br><span class="line">    <span class="built_in">this</span>.study = <span class="function"><span class="keyword">function</span>(<span class="params">active</span>) </span>&#123;</span><br><span class="line">        <span class="built_in">console</span>.log(active));</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// 创建对象时需要加 new！</span></span><br><span class="line"><span class="keyword">var</span> xiaoming = <span class="keyword">new</span> Student(<span class="string">&#x27; 菜鸟小铭 &#x27;</span>,<span class="number">18</span>,<span class="string">&#x27; 男 &#x27;</span>);</span><br><span class="line"><span class="comment">// 调用对象</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="keyword">typeof</span> xiaoming);<span class="comment">// 输出 object</span></span><br><span class="line"><span class="built_in">console</span>.log(xiaoming.name);<span class="comment">// 输出菜鸟小铭</span></span><br><span class="line"><span class="built_in">console</span>.log(xiaoming[<span class="string">&#x27;sex&#x27;</span>]);<span class="comment">// 输出男</span></span><br><span class="line">xiaoming.study(<span class="string">&#x27;study&#x27;</span>);</span><br></pre></td></tr></table></figure>

<ul>
<li>注意！构造函数首字母大写</li>
<li>构造函数不需要 return 就可以返回一个对象</li>
<li>属性和方法前面必须加 this</li>
</ul>
<h5 id="new 的作用"><a href="#new 的作用" class="headerlink" title="new 的作用"></a>new 的作用</h5><ol>
<li> new 之后创建了一个空的对象</li>
<li> 里面的 this 指针指向空对象</li>
<li> 然后执行属性和方法</li>
<li> 然后返回这个对象</li>
</ol>
<h3 id="遍历对象属性 -for…in 循环"><a href="# 遍历对象属性 -for…in 循环" class="headerlink" title="遍历对象属性 (for…in 循环)"></a>遍历对象属性 (for…in 循环)</h3><ul>
<li>   for in 循环可以用于数组和对象</li>
<li>   代码示例：</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> obj = &#123;</span><br><span class="line">    <span class="attr">name</span> : <span class="string">&#x27; 代码小铭 &#x27;</span>,</span><br><span class="line">    <span class="attr">age</span> : <span class="number">18</span>,</span><br><span class="line">    <span class="attr">gender</span> : man,</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">var</span> k <span class="keyword">in</span> obj) &#123;</span><br><span class="line">    <span class="built_in">console</span>.log(k); <span class="comment">// 得到的是属性名</span></span><br><span class="line">    <span class="built_in">console</span>.log(obj[k]); <span class="comment">// 得到的是属性值</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>小知识：for…in 里面的变量喜欢用 k 或者 key</li>
<li>也可以遍历出方法</li>
</ul>
<h3 id="JavaScript 内置对象"><a href="#JavaScript 内置对象" class="headerlink" title="JavaScript 内置对象"></a>JavaScript 内置对象</h3><ul>
<li><p>内置对象：js 语言自带的对象</p>
</li>
<li><p>文档网站推荐：<a target="_blank" rel="external nofollow noopener noreferrer" href="https://developer.mozilla.org/zh-CN/">MDN 网站</a></p>
</li>
</ul>
<h4 id="Math 对象"><a href="#Math 对象" class="headerlink" title="Math 对象"></a>Math 对象</h4><ul>
<li>   Math 对象不是构造函数，所以不需要 new，直接使用就可以</li>
<li>   代码示例：</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Math</span>.PI);</span><br><span class="line"><span class="comment">// 输出 3.14……</span></span><br></pre></td></tr></table></figure>

<ul>
<li>里面有 max 方法<ul>
<li>参数不限个数</li>
<li>如果有不是数据的参数，则会返回 NaN</li>
<li>如果没有参数返回<code>-Infinity</code></li>
</ul>
</li>
</ul>
<h5 id="绝对值和取整"><a href="# 绝对值和取整" class="headerlink" title="绝对值和取整"></a>绝对值和取整</h5><ul>
<li>   代码示例：</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 绝对值</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Math</span>.abs(-<span class="number">1</span>));</span><br><span class="line"><span class="comment">// 输出 1</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Math</span>.abs(<span class="string">&#x27;-1&#x27;</span>));</span><br><span class="line"><span class="comment">// 同样输出 1 (隐式转换)</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 向下取整</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Math</span>.floor(<span class="number">1.9</span>));</span><br><span class="line"><span class="comment">// 输出 1</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 向上取整</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Math</span>.cell(<span class="number">1.1</span>));</span><br><span class="line"><span class="comment">// 输出 2</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 四舍五入</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Math</span>.round(<span class="number">1.5</span>));</span><br><span class="line"><span class="comment">// 输出 2</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 四舍五入特例 (.5 的时候往大了取)</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Math</span>.round(-<span class="number">1.5</span>));</span><br><span class="line"><span class="comment">// 输出 -1</span></span><br></pre></td></tr></table></figure>

<h5 id="随机数 -random"><a href="# 随机数 -random" class="headerlink" title="随机数 (random)"></a>随机数 (random)</h5><ul>
<li>   random 返回 0 到 1 之间的小数 (可以取到 0，取不到 1)</li>
<li>   代码示例：</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Math</span>.random());</span><br><span class="line"></span><br><span class="line"><span class="comment">// 两个数之间的随机整数，包括这两个数</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">getRandomIntInclusive</span>(<span class="params">min, max</span>) </span>&#123;</span><br><span class="line">  min = <span class="built_in">Math</span>.ceil(min);</span><br><span class="line">  max = <span class="built_in">Math</span>.floor(max);</span><br><span class="line">  <span class="keyword">return</span> <span class="built_in">Math</span>.floor(<span class="built_in">Math</span>.random() * (max - min + <span class="number">1</span>)) + min; <span class="comment">// 含最大值，含最小值</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="Date 对象"><a href="#Date 对象" class="headerlink" title="Date 对象"></a>Date 对象</h4><ul>
<li>   时间开始于 1970 年 1 月 1 日</li>
<li>   Date 是构造函数，需要 new 一个日期对象</li>
<li>   代码示例：</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> date = <span class="keyword">new</span> <span class="built_in">Date</span>();</span><br><span class="line"></span><br><span class="line"><span class="comment">// 如果没有参数，返回当前系统时间</span></span><br><span class="line"><span class="built_in">console</span>.log(date);</span><br><span class="line"><span class="comment">// 输出 Tue Mar 10 2020 20:43:20 GMT+0800 (中国标准时间)</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 数字型</span></span><br><span class="line"><span class="keyword">var</span> date1 = <span class="keyword">new</span> <span class="built_in">Date</span>(<span class="number">2019</span>,<span class="number">10</span>,<span class="number">01</span>);</span><br><span class="line"><span class="built_in">console</span>.log(date1);</span><br><span class="line"><span class="comment">// 输出 2019 年 11 月 1 日 (比实际月份大 1 月)</span></span><br><span class="line"><span class="comment">// 因为月份是从 0 月开始算的</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 字符串型</span></span><br><span class="line"><span class="keyword">var</span> date2 = <span class="keyword">new</span> <span class="built_in">Date</span>(<span class="string">&#x27;2019-10-1 20:03:20&#x27;</span>);</span><br><span class="line"><span class="comment">// 正常输出</span></span><br></pre></td></tr></table></figure>

<h5 id="日期格式化"><a href="# 日期格式化" class="headerlink" title="日期格式化"></a>日期格式化</h5><ul>
<li>   推荐看 <a target="_blank" rel="external nofollow noopener noreferrer" href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Date">MDN</a> 里的 get 开头的属性</li>
<li>   以 dateFullYear，getMonth 为例</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> date = <span class="keyword">new</span> <span class="built_in">Date</span>();</span><br><span class="line"><span class="built_in">console</span>.log(date.getFullYear());</span><br><span class="line"><span class="comment">// 输出 2020</span></span><br><span class="line"><span class="built_in">console</span>.log(date.getMonth());</span><br><span class="line"><span class="comment">// 输出结果比实际少 1 月 (月份是从零开始算的)</span></span><br></pre></td></tr></table></figure>

<ul>
<li>注意：周日返回为 0 (可以使用数组来更改)</li>
<li>想要分钟等出现 02 这样，三元运算符判断，字符串连接</li>
</ul>
<h5 id="时间戳 - 距离 1970 年的毫秒数"><a href="# 时间戳 - 距离 1970 年的毫秒数" class="headerlink" title="时间戳 (距离 1970 年的毫秒数)"></a>时间戳 (距离 1970 年的毫秒数)</h5><ul>
<li>   valueOf()，getTime()，+new Date()，Date.now()四种方法</li>
<li>   应用：程序运行时间</li>
<li>   代码示例：</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> date =<span class="keyword">new</span> <span class="built_in">Date</span>();</span><br><span class="line"><span class="built_in">console</span>.log(date.valueOf());</span><br><span class="line"><span class="built_in">console</span>.log(date.getTime());</span><br><span class="line"></span><br><span class="line"><span class="comment">// 简单写法 (最常用)</span></span><br><span class="line"><span class="keyword">var</span> date1 = +<span class="keyword">new</span> <span class="built_in">Date</span>();</span><br><span class="line"><span class="built_in">console</span>.log(date1);</span><br><span class="line"></span><br><span class="line"><span class="comment">// H5 新增方法</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Date</span>.noe());</span><br></pre></td></tr></table></figure>

<h6 id="时间戳示例：倒计时"><a href="# 时间戳示例：倒计时" class="headerlink" title="时间戳示例：倒计时"></a>时间戳示例：倒计时</h6><ul>
<li>   不能直接用时分秒直接减(会出现负数)，但是可以用时间戳可以直接减</li>
<li>   代码实例：</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">countDown</span>(<span class="params">times</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">var</span> nowTime = +<span class="keyword">new</span> <span class="built_in">Date</span>();</span><br><span class="line">    <span class="keyword">var</span> inputTime = +<span class="keyword">new</span> <span class="built_in">Date</span>(time);</span><br><span class="line">    <span class="keyword">var</span> times = inputTime - nowTime;</span><br><span class="line">    times /= <span class="number">1000</span>;</span><br><span class="line">    <span class="keyword">var</span> dd = <span class="built_in">parseInt</span>(times / <span class="number">60</span> / <span class="number">60</span> / <span class="number">24</span>);</span><br><span class="line">    <span class="keyword">var</span> hh = <span class="built_in">parseInt</span>(times / <span class="number">60</span> / <span class="number">60</span> % <span class="number">24</span>);</span><br><span class="line">    <span class="keyword">var</span> mm = <span class="built_in">parseInt</span>(times / <span class="number">60</span> % <span class="number">60</span>);</span><br><span class="line">    <span class="keyword">var</span> ss = <span class="built_in">parseInt</span>(times % <span class="number">60</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="数组对象 -Array"><a href="# 数组对象 -Array" class="headerlink" title="数组对象 (Array)"></a>数组对象 (Array)</h4><ul>
<li>   new 新建数组详解：</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = <span class="keyword">new</span> <span class="built_in">Array</span>(<span class="number">2</span>);</span><br><span class="line"><span class="comment">// 里面的 2 代表数组长度为 2</span></span><br><span class="line"><span class="keyword">var</span> arr = <span class="keyword">new</span> <span class="built_in">Array</span>(<span class="number">2</span> , <span class="number">3</span>);</span><br><span class="line"><span class="comment">// 新建一个 [2,3] 的数组</span></span><br></pre></td></tr></table></figure>

<h5 id="检测是否为数组"><a href="# 检测是否为数组" class="headerlink" title="检测是否为数组"></a>检测是否为数组</h5><ul>
<li>   用 instanceof 运算符来检测</li>
<li>   代码示例：</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> srr = [];</span><br><span class="line"><span class="built_in">console</span>.log(arr <span class="keyword">instanceof</span> <span class="built_in">Array</span>);</span><br><span class="line"><span class="comment">// 输出结果 true</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Math</span> <span class="keyword">instanceof</span> <span class="built_in">Object</span>);</span><br><span class="line"><span class="comment">// 输出结果 true</span></span><br></pre></td></tr></table></figure>

<ul>
<li><a target="_blank" rel="external nofollow noopener noreferrer" href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/instanceof">instanceof 详解</a></li>
<li>感觉是判断这个对象是否是这个构造函数的对象 (因为数组的类型其实也是对象)</li>
</ul>
<hr>
<ul>
<li>   用 Array.isArray(参数) 来判断 (H5 新增方法)</li>
<li>   代码示例：</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [];</span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Array</span>.isArray(arr));</span><br><span class="line"><span class="comment">// 输出结果 true</span></span><br></pre></td></tr></table></figure>

<ul>
<li>和 instanceof 的区别：<ul>
<li>isArray 能检测到 iframes</li>
</ul>
</li>
</ul>
<h5 id="添加和删除数组元素"><a href="# 添加和删除数组元素" class="headerlink" title="添加和删除数组元素"></a>添加和删除数组元素</h5><table>
<thead>
<tr>
<th>方法名</th>
<th>说明</th>
<th>返回值</th>
</tr>
</thead>
<tbody><tr>
<td>push(参数)</td>
<td>在末尾添加一个或多个元素</td>
<td>返回新数组的长度</td>
</tr>
<tr>
<td>unshift(参数)</td>
<td>在开头加入一个或多个元素</td>
<td>返回新数组的长度</td>
</tr>
<tr>
<td>pop()</td>
<td>删除数组最后一个元素</td>
<td>返回删除元素的值</td>
</tr>
<tr>
<td>shift()</td>
<td>删除数组第一个元素</td>
<td>返回删除元素的值</td>
</tr>
<tr>
<td>.splice(index,howmany,item)</td>
<td>删除数组指定元素</td>
<td>返回删除元素的值</td>
</tr>
<tr>
<td>slice(begin,end)</td>
<td>截取从 begin 到 end</td>
<td>返回新数组</td>
</tr>
</tbody></table>
<ul>
<li><p>详解 .splice 使用方法：</p>
<ul>
<li><p>index：删除哪一位的元素</p>
</li>
<li><p>howmany：删除这位的元素多少个</p>
</li>
<li><p>item：替换这个元素的值</p>
</li>
<li><p>代码示例：</p>
</li>
</ul>
</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = <span class="keyword">new</span> <span class="built_in">Array</span>(<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>);</span><br><span class="line"><span class="built_in">console</span>.log(arr.push(<span class="number">4</span>,<span class="string">&#x27;tom&#x27;</span>));</span><br><span class="line"><span class="comment">// 输出 5</span></span><br><span class="line"><span class="built_in">console</span>.log(arr);</span><br><span class="line"><span class="comment">// 输出[1,2,3,4,&quot;tom&quot;]</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> arr = <span class="keyword">new</span> <span class="built_in">Array</span>(<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>);</span><br><span class="line"><span class="built_in">console</span>.log(arr.unshift(<span class="number">0</span>));</span><br><span class="line"><span class="comment">// 输出 4</span></span><br><span class="line"><span class="built_in">console</span>.log(arr);</span><br><span class="line"><span class="comment">// 输出[0,1,2,3]</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> arr = <span class="keyword">new</span> <span class="built_in">Array</span>(<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>);</span><br><span class="line"><span class="built_in">console</span>.log(arr.pop());</span><br><span class="line"><span class="comment">// 输出 3 (被删除的那个元素)</span></span><br><span class="line"><span class="built_in">console</span>.log(arr);</span><br><span class="line"><span class="comment">// 输出[1,2]</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> arr = <span class="keyword">new</span> <span class="built_in">Array</span>(<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>);</span><br><span class="line"><span class="built_in">console</span>.log(arr.shift());</span><br><span class="line"><span class="comment">// 输出 1 (被删除的那个元素)</span></span><br><span class="line"><span class="built_in">console</span>.log(arr);</span><br><span class="line"><span class="comment">// 输出[2,3]</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> arr = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>]</span><br><span class="line">arr.splice(<span class="number">2</span>,<span class="number">2</span>,<span class="number">0</span>);</span><br><span class="line"><span class="built_in">console</span>.log(arr);</span><br><span class="line"><span class="comment">// 输出[1,2,0,0,5]</span></span><br></pre></td></tr></table></figure>

<h5 id="数组排序"><a href="# 数组排序" class="headerlink" title="数组排序"></a>数组排序</h5><table>
<thead>
<tr>
<th>方法名</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>reverse()</td>
<td>颠倒数组中元素的顺序</td>
</tr>
<tr>
<td>sort()</td>
<td>对数组元素进行排序 (冒泡排序)</td>
</tr>
</tbody></table>
<ul>
<li>   返回值是更新后的数组</li>
<li>   代码示例：</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>];</span><br><span class="line">arr.reverse();</span><br><span class="line"><span class="built_in">console</span>.log(arr);</span><br><span class="line"><span class="comment">// 输出[3,2,1]</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> arr = [<span class="number">7</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">6</span>,<span class="number">8</span>,<span class="number">9</span>,<span class="number">1</span>];</span><br><span class="line">arr.sort();</span><br><span class="line"><span class="built_in">console</span>.log(arr);</span><br><span class="line"><span class="comment">// 输出[1,3,4,6,7,8,9]</span></span><br></pre></td></tr></table></figure>

<ul>
<li>   sort 排序是有缺陷的，他会先判断十位再判断个位</li>
<li>   就会出现以下情况：</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="number">13</span>,<span class="number">4</span>,<span class="number">45</span>,<span class="number">7</span>,<span class="number">77</span>,<span class="number">1</span>];</span><br><span class="line">arr.sort();</span><br><span class="line"><span class="built_in">console</span>.log(arr);</span><br><span class="line"><span class="comment">// 输出 [1,13,4,45,7,77]</span></span><br></pre></td></tr></table></figure>

<ul>
<li>   解决方法：</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="number">13</span>,<span class="number">4</span>,<span class="number">45</span>,<span class="number">7</span>,<span class="number">77</span>,<span class="number">1</span>];</span><br><span class="line">arr.sort(<span class="function"><span class="keyword">function</span>(<span class="params">a,b</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> a - b; <span class="comment">// 升序排列</span></span><br><span class="line">&#125;)</span><br><span class="line"><span class="built_in">console</span>.log(arr);</span><br><span class="line"><span class="comment">// 输出[1,4,7,13,45,77]</span></span><br></pre></td></tr></table></figure>

<ul>
<li>这里用 a - b 是升序排列，b - a 就是降序排列</li>
</ul>
<h5 id="数组索引"><a href="# 数组索引" class="headerlink" title="数组索引"></a>数组索引</h5><table>
<thead>
<tr>
<th>方法名</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>indexOf()</td>
<td>数组查找指定元素的第一个索引</td>
</tr>
<tr>
<td>lastIndexOf()</td>
<td>数组查找指定元素最后一个索引</td>
</tr>
</tbody></table>
<ul>
<li>   返回的是元素的下标</li>
<li>   如果不存在则返回 -1</li>
<li>   代码示例：</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>,<span class="number">2</span>];</span><br><span class="line"><span class="built_in">console</span>.log(arr.indexOf(<span class="number">2</span>));</span><br><span class="line"><span class="comment">// 返回 1</span></span><br><span class="line"><span class="built_in">console</span>.log(arr.lastIndexOf(<span class="number">2</span>));</span><br><span class="line"><span class="comment">// 返回 5</span></span><br></pre></td></tr></table></figure>

<h6 id="数组索引实例：数组去重"><a href="# 数组索引实例：数组去重" class="headerlink" title="数组索引实例：数组去重"></a>数组索引实例：数组去重</h6><ul>
<li>   我的解题思路：如果前面索引和后面索引的值相等，那么直接跳过；如果前面的索引和后面的索引不等，则去除后面索引到的元素，并且 key-1 (为了防止出现多个重复)</li>
<li>   代码示例：</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="string">&#x27;c&#x27;</span>, <span class="string">&#x27;a&#x27;</span>, <span class="string">&#x27;z&#x27;</span>, <span class="string">&#x27;a&#x27;</span>, <span class="string">&#x27;x&#x27;</span>, <span class="string">&#x27;a&#x27;</span>, <span class="string">&#x27;x&#x27;</span>, <span class="string">&#x27;a&#x27;</span>, <span class="string">&#x27;c&#x27;</span>, <span class="string">&#x27;n&#x27;</span>];</span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">var</span> key = <span class="number">0</span>; key &lt; arr.length; key++) &#123;</span><br><span class="line">    <span class="keyword">if</span> (arr.indexOf(arr[key]) == arr.lastIndexOf(arr[key])) &#123;</span><br><span class="line">        <span class="keyword">continue</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span> (arr[key] == arr[arr.lastIndexOf(arr[key])]) &#123;</span><br><span class="line">        arr.splice(arr.lastIndexOf(arr[key]), <span class="number">1</span>);</span><br><span class="line">        key--;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="built_in">console</span>.log(arr);</span><br></pre></td></tr></table></figure>

<ul>
<li>   老师的解法：遍历旧数组，然后查询新数组是否有重复，如果没有重复则添加</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="string">&#x27;c&#x27;</span>,<span class="string">&#x27;a&#x27;</span>,<span class="string">&#x27;z&#x27;</span>,<span class="string">&#x27;a&#x27;</span>,<span class="string">&#x27;x&#x27;</span>,<span class="string">&#x27;a&#x27;</span>,<span class="string">&#x27;x&#x27;</span>,<span class="string">&#x27;a&#x27;</span>,<span class="string">&#x27;c&#x27;</span>,<span class="string">&#x27;n&#x27;</span>];</span><br><span class="line"><span class="keyword">var</span> newArr = [];</span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">var</span> i = <span class="number">0</span>; i &lt; arr.length; i++) &#123;</span><br><span class="line">    <span class="keyword">if</span> (newArr.indexOf(arr[i]) == -<span class="number">1</span>) &#123;</span><br><span class="line">        newArr.push(arr[i]);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="built_in">console</span>.log(newArr);</span><br></pre></td></tr></table></figure>

<blockquote>
<p>老师的方法比我的方法简单一万倍</p>
</blockquote>
<h5 id="数组转化为字符串"><a href="# 数组转化为字符串" class="headerlink" title="数组转化为字符串"></a>数组转化为字符串</h5><table>
<thead>
<tr>
<th>方法名</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>toString()</td>
<td>数组转化为字符串，逗号分隔</td>
</tr>
<tr>
<td>join(‘分隔符’)</td>
<td>分隔符分割开 (什么都不写默认是逗号)</td>
</tr>
</tbody></table>
<ul>
<li>   返回值是转换好的字符串</li>
<li>   代码示例：</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>];</span><br><span class="line"><span class="built_in">console</span>.log(arr.toString());</span><br><span class="line"><span class="comment">// 输出 1,2,3</span></span><br><span class="line"><span class="built_in">console</span>.log(arr.join(<span class="string">&#x27;&#x27;</span>));</span><br><span class="line"><span class="comment">// 输出 123</span></span><br></pre></td></tr></table></figure>

<h4 id="字符串对象"><a href="# 字符串对象" class="headerlink" title="字符串对象"></a>字符串对象</h4><ul>
<li>   字符串是简单数据类型，但是有属性和方法</li>
<li>   基本包装类型：把简单数据类型包装成复杂数据类型 (String, Number, Boolean)</li>
<li>   过程：</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> str = <span class="string">&#x27; 菜鸟小铭 &#x27;</span>;</span><br><span class="line"><span class="keyword">var</span> temp = <span class="keyword">new</span> <span class="built_in">String</span>(<span class="string">&#x27; 菜鸟小铭 &#x27;</span>);</span><br><span class="line">str = temp;</span><br><span class="line">temp = <span class="literal">null</span>; <span class="comment">// 销毁中间变量</span></span><br></pre></td></tr></table></figure>

<h5 id="字符串的不可变"><a href="# 字符串的不可变" class="headerlink" title="字符串的不可变"></a>字符串的不可变</h5><ul>
<li><p>用户声明一个字符串并且赋初值后，再拿另一个值去覆盖这个变量，初始的赋值并没有被销毁，而只是变量名指向了另一个值 (地址改变)</p>
<ul>
<li>不可变的体现：</li>
</ul>
</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> str = <span class="string">&#x27;&#x27;</span>;</span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">var</span> i = <span class="number">0</span>; i &lt; <span class="number">10000000</span>; i++) &#123;</span><br><span class="line">    str += i;</span><br><span class="line">&#125;</span><br><span class="line"><span class="built_in">console</span>.log(str);</span><br></pre></td></tr></table></figure>

<ul>
<li>根据 chrome 的任务管理器来看，循环一千万次需要内存 629.34MB 内存 (如果电脑内存不是特别大不建议尝试)</li>
<li>所以不要随意拼接字符串</li>
</ul>
<h5 id="在字符串里面查找字符"><a href="# 在字符串里面查找字符" class="headerlink" title="在字符串里面查找字符"></a>在字符串里面查找字符</h5><table>
<thead>
<tr>
<th>方法名</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>indexOf(‘要查找的字符’, 开始的位置)</td>
<td>从前往后找，只找第一个</td>
</tr>
<tr>
<td>lastIndexOf(‘要查找的字符’, 开始的位置)</td>
<td>从后往前找，只找第一个匹配的</td>
</tr>
</tbody></table>
<ul>
<li>   返回在字符串里的位置，找不到返回 -1</li>
<li>   代码示例：</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> str = <span class="string">&#x27;JavaScript!&#x27;</span>;</span><br><span class="line"><span class="built_in">console</span>.log(str.indexOf(<span class="string">&#x27;S&#x27;</span>));</span><br><span class="line"><span class="comment">// 返回 4</span></span><br><span class="line"><span class="keyword">var</span> str = <span class="string">&#x27;assa&#x27;</span>;</span><br><span class="line"><span class="built_in">console</span>.log(str.indexOf(<span class="string">&#x27;a&#x27;</span>,<span class="number">1</span>));</span><br><span class="line"><span class="comment">// 返回 3</span></span><br><span class="line"><span class="comment">// lastIndexOf 同理</span></span><br></pre></td></tr></table></figure>

<h5 id="根据位置返回字符"><a href="# 根据位置返回字符" class="headerlink" title="根据位置返回字符"></a>根据位置返回字符</h5><table>
<thead>
<tr>
<th>方法名</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>charAt(index)</td>
<td>返回指定位置的字符</td>
</tr>
<tr>
<td>charCodeAt(index)</td>
<td>获取指定位置字符的 ASSII 码</td>
</tr>
<tr>
<td>str[index]</td>
<td>获取指定位置字符 (H5 新增)</td>
</tr>
</tbody></table>
<ul>
<li>   代码示例：</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> str = <span class="string">&#x27;JavaScript!&#x27;</span>;</span><br><span class="line"><span class="built_in">console</span>.log(charAt(<span class="number">5</span>));</span><br><span class="line"><span class="comment">// 输出 c</span></span><br><span class="line"><span class="built_in">console</span>.log(charCodeAt(<span class="number">5</span>));</span><br><span class="line"><span class="comment">// 输出 99</span></span><br><span class="line">cosnle.log(str[<span class="number">5</span>]);</span><br><span class="line"><span class="comment">// 输出 c</span></span><br></pre></td></tr></table></figure>

<ul>
<li>可以使用对象名 [‘属性’] 的方法来获取对象里面的属性及属性的值</li>
</ul>
<h5 id="字符串的操作"><a href="# 字符串的操作" class="headerlink" title="字符串的操作"></a>字符串的操作</h5><table>
<thead>
<tr>
<th>方法名</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>concat(str1,str2)</td>
<td>连接 数组 / 字符串，等效于 +</td>
</tr>
<tr>
<td>substr(start,length)</td>
<td>截取字符串 从 start 处开始截取，截取 length 这么长 <strong>重要</strong></td>
</tr>
<tr>
<td>replace(‘被替换的字符’,‘替换为的字符’)</td>
<td>替换字符 (只替换第一个)</td>
</tr>
<tr>
<td>split(‘分隔符’)</td>
<td>字符转换为数组 (和 join 类似)</td>
</tr>
</tbody></table>
<ul>
<li>   代码示例：</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> str = <span class="string">&#x27;abca&#x27;</span>;</span><br><span class="line"><span class="built_in">console</span>.log(str.replace(<span class="string">&#x27;a&#x27;</span>,<span class="string">&#x27;z&#x27;</span>));</span><br><span class="line"><span class="comment">// 输出 zbca</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> str = <span class="string">&#x27;a,b,c&#x27;</span>;</span><br><span class="line"><span class="built_in">console</span>.log(str.split(<span class="string">&#x27;,&#x27;</span>))</span><br><span class="line"><span class="comment">// 输出 [a,b,c]</span></span><br></pre></td></tr></table></figure>

<h2 id="JavaScript 数据类型"><a href="#JavaScript 数据类型" class="headerlink" title="JavaScript 数据类型"></a>JavaScript 数据类型 </h2><h3 id="简单数据类型"><a href="# 简单数据类型" class="headerlink" title="简单数据类型"></a> 简单数据类型</h3><ul>
<li><p>包括：Number，String，Bollean，undefined，null</p>
</li>
<li><p>null 是一个对象</p>
<ul>
<li>应用：有个变量以后打算存对象，可以用 null 占位</li>
</ul>
</li>
<li><p>在栈中储存数据</p>
</li>
<li><p>简单数据类型传参</p>
<ul>
<li>直接把栈里面的值覆盖掉</li>
</ul>
</li>
</ul>
<h3 id="复杂数据类型"><a href="# 复杂数据类型" class="headerlink" title="复杂数据类型"></a>复杂数据类型</h3><ul>
<li><p>用 new 创建的类型</p>
</li>
<li><p>包括 Object，Array</p>
</li>
<li><p>在堆中储存：在栈中存放地址，地址指向堆，在堆里面存放数据</p>
</li>
<li><p>复杂数据类型传参</p>
<ul>
<li>先找到放在栈中的变量名，取出里面的地址，找到地址指向的堆，再修改里面的变量</li>
</ul>
</li>
</ul>
<blockquote>
<p>本文转载自<a target="_blank" rel="external nofollow noopener noreferrer" href="https://blog.csdn.net/weixin_46170034/article/details/104807480">https://blog.csdn.net/weixin_46170034/article/details/104807480</a></p>
</blockquote>

    </div>

    
    
    
      
  <div class="popular-posts-header">相关文章推荐</div>
  <ul class="popular-posts">
    <li class="popular-posts-item">
      <div class="popular-posts-title"><a href="\archives\35d65417.html" rel="bookmark">JavaScript 之 WebAPI 学习 1</a></div>
    </li>
    <li class="popular-posts-item">
      <div class="popular-posts-title"><a href="\archives\dbd8353b.html" rel="bookmark">JavaScript 之 WebAPI 学习 3</a></div>
    </li>
    <li class="popular-posts-item">
      <div class="popular-posts-title"><a href="\archives\45bca098.html" rel="bookmark">JavaScript 之 WebAPI 学习 4</a></div>
    </li>
    <li class="popular-posts-item">
      <div class="popular-posts-title"><a href="\archives\5606f168.html" rel="bookmark">JavaScript 基础语法 1</a></div>
    </li>
    <li class="popular-posts-item">
      <div class="popular-posts-title"><a href="\archives\cf0fa0d2.html" rel="bookmark">JavaScript 基础语法 2</a></div>
    </li>
  </ul>

        <div class="reward-container">
  <div>感谢各位打赏的小伙伴</div>
  <button onclick="var qr = document.getElementById('qr'); qr.style.display = (qr.style.display === 'none') ? 'block' : 'none';">
    打赏
  </button>
  <div id="qr" style="display: none;">
      
      <div style="display: inline-block;">
        <img src="/images/wechatpay.png" alt="肥肉啊肥肉你在哪 微信支付">
        <p>微信支付</p>
      </div>
      
      <div style="display: inline-block;">
        <img src="/images/alipay.png" alt="肥肉啊肥肉你在哪 支付宝">
        <p>支付宝</p>
      </div>

  </div>
</div>

        

<div>
<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>肥肉啊肥肉你在哪
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="http://fat_fat_where_are_you.gitee.io/archives/b8089044.html" title="JavaScript 基础语法 3">http://fat_fat_where_are_you.gitee.io/archives/b8089044.html</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="external nofollow noopener noreferrer" target="_blank"><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！
  </li>
</ul>
</div>


      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/JavaScript/" rel="tag"><i class="fas fa-tags"></i> JavaScript</a>
          </div>

        
  <div class="post-widgets">
    <div class="wp_rating">
      <div id="wpac-rating"></div>
    </div>
  </div>


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/archives/cf0fa0d2.html" rel="prev" title="JavaScript 基础语法 2">
      <i class="fa fa-chevron-left"></i> JavaScript 基础语法 2
    </a></div>
      <div class="post-nav-item">
    <a href="/archives/acdf05ad.html" rel="next" title="JavaScript 之 WebAPI 学习 2">
      JavaScript 之 WebAPI 学习 2 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#JavaScript%20%E5%9F%BA%E7%A1%80%E8%AF%AD%E6%B3%95"><span class="nav-text">JavaScript 基础语法</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#JavaScript%20%E5%87%BD%E6%95%B0"><span class="nav-text">JavaScript 函数</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#JavaScript%20%E5%87%BD%E6%95%B0%E4%BD%BF%E7%94%A8"><span class="nav-text">JavaScript 函数使用</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#arguments%20%E4%BD%BF%E7%94%A8%20-%E2%98%85"><span class="nav-text">arguments 使用(★)</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#arguments%20%E4%BD%BF%E7%94%A8%E6%A1%88%E4%BE%8B"><span class="nav-text">arguments 使用案例</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%87%BD%E6%95%B0%E5%A3%B0%E6%98%8E%E4%B8%A4%E7%A7%8D%E6%96%B9%E5%BC%8F"><span class="nav-text">函数声明两种方式</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%8F%98%E9%87%8F%E4%BD%9C%E7%94%A8%E5%9F%9F%EF%BC%88%E2%98%85%EF%BC%89"><span class="nav-text">变量作用域（★）</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%9D%97%E7%BA%A7%E4%BD%9C%E7%94%A8%E5%9F%9F%20-%20%E6%96%B0%E5%B1%9E%E6%80%A7"><span class="nav-text">块级作用域 (新属性)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%BD%9C%E7%94%A8%E5%9F%9F%E9%93%BE"><span class="nav-text">作用域链</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#JavaScript%20%E9%A2%84%E8%A7%A3%E6%9E%90%20-%E2%98%85"><span class="nav-text">JavaScript 预解析(★)</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%A2%84%E8%A7%A3%E6%9E%90%E5%AE%9E%E4%BE%8B"><span class="nav-text">预解析实例</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#JavaScript%20%E5%AF%B9%E8%B1%A1"><span class="nav-text">JavaScript 对象</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%88%9B%E5%BB%BA%E5%AF%B9%E8%B1%A1%E7%9A%84%E4%B8%89%E7%A7%8D%E6%96%B9%E5%BC%8F%20-%20%E8%87%AA%E5%AE%9A%E4%B9%89%E5%AF%B9%E8%B1%A1"><span class="nav-text">创建对象的三种方式 (自定义对象)</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E7%9B%B4%E6%8E%A5%E5%88%9B%E5%BB%BA%E5%AF%B9%E8%B1%A1"><span class="nav-text">直接创建对象</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%88%A9%E7%94%A8%20new-object%20%E5%88%9B%E5%BB%BA%E5%AF%B9%E8%B1%A1"><span class="nav-text">利用 new object 创建对象</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%88%A9%E7%94%A8%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0%E5%88%9B%E5%BB%BA%E5%AF%B9%E8%B1%A1%20-%E2%98%85"><span class="nav-text"> 利用构造函数创建对象(★)</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#new%20%E7%9A%84%E4%BD%9C%E7%94%A8"><span class="nav-text">new 的作用</span></a></li></ol></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%81%8D%E5%8E%86%E5%AF%B9%E8%B1%A1%E5%B1%9E%E6%80%A7%20-for%E2%80%A6in%20%E5%BE%AA%E7%8E%AF"><span class="nav-text">遍历对象属性 (for…in 循环)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#JavaScript%20%E5%86%85%E7%BD%AE%E5%AF%B9%E8%B1%A1"><span class="nav-text">JavaScript 内置对象</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#Math%20%E5%AF%B9%E8%B1%A1"><span class="nav-text">Math 对象</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#%E7%BB%9D%E5%AF%B9%E5%80%BC%E5%92%8C%E5%8F%96%E6%95%B4"><span class="nav-text">绝对值和取整</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E9%9A%8F%E6%9C%BA%E6%95%B0%20-random"><span class="nav-text">随机数 (random)</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#Date%20%E5%AF%B9%E8%B1%A1"><span class="nav-text">Date 对象</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#%E6%97%A5%E6%9C%9F%E6%A0%BC%E5%BC%8F%E5%8C%96"><span class="nav-text">日期格式化</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E6%97%B6%E9%97%B4%E6%88%B3%20-%20%E8%B7%9D%E7%A6%BB%201970%20%E5%B9%B4%E7%9A%84%E6%AF%AB%E7%A7%92%E6%95%B0"><span class="nav-text">时间戳 (距离 1970 年的毫秒数)</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#%E6%97%B6%E9%97%B4%E6%88%B3%E7%A4%BA%E4%BE%8B%EF%BC%9A%E5%80%92%E8%AE%A1%E6%97%B6"><span class="nav-text">时间戳示例：倒计时</span></a></li></ol></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E6%95%B0%E7%BB%84%E5%AF%B9%E8%B1%A1%20-Array"><span class="nav-text">数组对象 (Array)</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#%E6%A3%80%E6%B5%8B%E6%98%AF%E5%90%A6%E4%B8%BA%E6%95%B0%E7%BB%84"><span class="nav-text">检测是否为数组</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E6%B7%BB%E5%8A%A0%E5%92%8C%E5%88%A0%E9%99%A4%E6%95%B0%E7%BB%84%E5%85%83%E7%B4%A0"><span class="nav-text">添加和删除数组元素</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E6%95%B0%E7%BB%84%E6%8E%92%E5%BA%8F"><span class="nav-text">数组排序</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E6%95%B0%E7%BB%84%E7%B4%A2%E5%BC%95"><span class="nav-text">数组索引</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#%E6%95%B0%E7%BB%84%E7%B4%A2%E5%BC%95%E5%AE%9E%E4%BE%8B%EF%BC%9A%E6%95%B0%E7%BB%84%E5%8E%BB%E9%87%8D"><span class="nav-text">数组索引实例：数组去重</span></a></li></ol></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E6%95%B0%E7%BB%84%E8%BD%AC%E5%8C%96%E4%B8%BA%E5%AD%97%E7%AC%A6%E4%B8%B2"><span class="nav-text">数组转化为字符串</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%AF%B9%E8%B1%A1"><span class="nav-text">字符串对象</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%9A%84%E4%B8%8D%E5%8F%AF%E5%8F%98"><span class="nav-text">字符串的不可变</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E5%9C%A8%E5%AD%97%E7%AC%A6%E4%B8%B2%E9%87%8C%E9%9D%A2%E6%9F%A5%E6%89%BE%E5%AD%97%E7%AC%A6"><span class="nav-text">在字符串里面查找字符</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E6%A0%B9%E6%8D%AE%E4%BD%8D%E7%BD%AE%E8%BF%94%E5%9B%9E%E5%AD%97%E7%AC%A6"><span class="nav-text">根据位置返回字符</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%9A%84%E6%93%8D%E4%BD%9C"><span class="nav-text">字符串的操作</span></a></li></ol></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#JavaScript%20%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="nav-text">JavaScript 数据类型 </span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%AE%80%E5%8D%95%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="nav-text"> 简单数据类型</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%A4%8D%E6%9D%82%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="nav-text">复杂数据类型</span></a></li></ol></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="肥肉啊肥肉你在哪" src="/images/touxiang.gif">
  <p class="site-author-name" itemprop="name">肥肉啊肥肉你在哪</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">38</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">4</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">16</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/feirouafeirou" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;feirouafeirou" rel="external nofollow noopener noreferrer" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="http://wpa.qq.com/msgrd?v=3&uin=1729013657&site=qq&menu=yes" title="QQ → http:&#x2F;&#x2F;wpa.qq.com&#x2F;msgrd?v&#x3D;3&amp;uin&#x3D;1729013657&amp;site&#x3D;qq&amp;menu&#x3D;yes" rel="external nofollow noopener noreferrer" target="_blank"><i class="fab fa-qq fa-fw"></i>QQ</a>
      </span>
  </div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title"><i class="fa fa-link fa-fw"></i>
      友情链接
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <a href="http://www.woshipm.com/" title="http:&#x2F;&#x2F;www.woshipm.com" rel="external nofollow noopener noreferrer" target="_blank">人人都是产品经理</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="http://www.chanpin100.com/" title="http:&#x2F;&#x2F;www.chanpin100.com" rel="external nofollow noopener noreferrer" target="_blank">产品壹佰</a>
        </li>
    </ul>
  </div>

      </div>

    </div>
  </aside>

  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 2020 – 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">肥肉啊肥肉你在哪</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-area"></i>
    </span>
    <span title="站点总字数">237k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">3:35</span>
</div>

<div class="translate-style">
繁/简：<a id="translateLink" href="javascript:translatePage();">繁体
</a>
</div>
<script type="text/javascript" src="/js/tw_cn.js"></script>
<script type="text/javascript">
var defaultEncoding = 2; //网站编写字体是否繁体，1-繁体，2-简体
var translateDelay = 0; //延迟时间,若不在前, 要设定延迟翻译时间, 如100表示100ms,默认为0
var cookieDomain = "https://feirouafeirou.github.io/"; //Cookie地址, 一定要设定, 通常为你的网址
var msgToTraditionalChinese = "繁体"; //此处可以更改为你想要显示的文字
var msgToSimplifiedChinese = "简体"; //同上，但两处均不建议更改
var translateButtonId = "translateLink"; //默认互换id
translateInitilization();
</script>


        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script>
  <script src="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/lozad@1/dist/lozad.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>


  <script defer src="/lib/three/three.min.js"></script>


  



  <script>
  if (CONFIG.page.isPost) {
    wpac_init = window.wpac_init || [];
    wpac_init.push({
      widget: 'Rating',
      id    : 26171,
      el    : 'wpac-rating',
      color : 'fc6423'
    });
    (function() {
      if ('WIDGETPACK_LOADED' in window) return;
      WIDGETPACK_LOADED = true;
      var mc = document.createElement('script');
      mc.type = 'text/javascript';
      mc.async = true;
      mc.src = '//embed.widgetpack.com/widget.js';
      var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(mc, s.nextSibling);
    })();
  }
  </script>

  
<script src="/js/local-search.js"></script>













  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : false,
      appId      : 'puzQn5yHhkbtBj2VGFbqJ4FE-MdYXbMMI',
      appKey     : 'lmcgKM2surcxNxMRiqInHjkU',
      placeholder: "Just go go",
      avatar     : 'retro',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : true,
      lang       : '' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>
<div class="moon-menu">
  <div class="moon-menu-items">
    
    <div id="moon-menu-item-back2bottom" class="moon-menu-item" onclick="back2bottom()">
      <i class="fa fa-chevron-down"></i>    </div>
    
    <div id="moon-menu-item-back2top" class="moon-menu-item" onclick="back2top()">
      <i class="fa fa-chevron-up"></i>    </div>
    
  </div>
  <div class="moon-menu-button">
    <svg class="moon-menu-bg">
      <circle class="moon-menu-cricle" cx="50%" cy="50%" r="44%"/>
      <circle class="moon-menu-border" cx="50%" cy="50%" r="48%"/>
    </svg>
    <div class="moon-menu-content">
      <div class="moon-menu-icon"><i class="fas fa-ellipsis-v"></i></div>
      <div class="moon-menu-text"></div>
    </div>
  </div>
</div><script src="/js/injector.js"></script>
<!-- 数字雨 -->
<!-- <canvas id="canvas" width="1440" height="900" ></canvas> -->
<!-- <script type="text/javascript" src="/js/src/DigitalRain.js"></script> -->
<!-- 页面点击小红心 -->
<script type="text/javascript" src="/js/src/clicklove.js"></script>
<!--浏览器搞笑标题-->
<script type="text/javascript" src="/js/FunnyTitle.js"></script>
<!-- Live2D看板娘 -->
<!-- <script src="/live2d-widget/autoload.js"></script> -->
<!-- <script src="https://feirouafeirou.github.io/live2d-widget/autoload.js"></script> -->
<!-- 网页音乐播放器 -->
<!-- <link rel="stylesheet" href="/dist/APlayer.min.css">
<div id="aplayer"></div>
<script type="text/javascript" src="/dist/APlayer.min.js"></script>
<script type="text/javascript" src="/dist/music.js"></script> -->
</body>

</html>
